﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataAccess
{
    public class DataAccessEmploy
    {
        public static List<Model.Employ> GetEmployByIdAndPassword(Model.Employ user)
        {
            SSDDEntities.Instance.DiscardChanges();
            return (from q in SSDDEntities.Instance.Employs
                    where q.EmployPassword == user.EmployPassword
                          && q.EmployId == user.EmployId
                    select q).ToList();
        }

        public static void UpdateEmployee(Model.Employ newEmployee)
        {
            SSDDEntities.Instance.DiscardChanges();
            var e = (from emp in SSDDEntities.Instance.Employs
                     where emp.EmployId == newEmployee.EmployId
                     select emp).First();
            e.EmployName = newEmployee.EmployName;
            e.EmployPassword = newEmployee.EmployPassword;
            e.EmployPhone = newEmployee.EmployPhone;
            e.EmployCharge = newEmployee.EmployCharge;
            e.EmployAddress = newEmployee.EmployAddress;
            e.BranchId = newEmployee.BranchId;
            e.Branch = null;

            SSDDEntities.Instance.SaveChanges();
        }

        public static void InsertEmployee(Model.Employ newEmployee)
        {
            SSDDEntities.Instance.DiscardChanges();
            SSDDEntities.Instance.Employs.Add(newEmployee);
            SSDDEntities.Instance.SaveChanges();
        }
    }
}
